package com.ruoyi.stock.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.stock.domain.StockInventory;
import com.ruoyi.stock.domain.vo.WarehouseInStockVo;
import com.ruoyi.stock.mapper.WarehouseInStockMapper;
import com.ruoyi.stock.service.WarehouseInStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author: YwaiX
 * @Version: 1.0
 * @Date: Created in 2024-10-30 16:35:48
 * @Description:
 */

@Service
public class WarehouseInStockServiceImpl implements WarehouseInStockService {

    @Autowired
    private WarehouseInStockMapper warehouseInStockMapper;

    @Override
    public WarehouseInStockVo list(Integer warehouseInInfoId ,Integer goodsType) {
        return warehouseInStockMapper.list(warehouseInInfoId,goodsType);
    }

    @Transactional
    @Override
    public Integer updateWarehouseId(Integer warehouseInInfoId, Integer warehouseId, String goodsNo, Integer number, Long userId) {
        //先查询库存表有没有物料
        List<StockInventory> list = warehouseInStockMapper.selectInventory(warehouseId, goodsNo);
        //如果是空,则添加,否则修改
        if (list.isEmpty()) {
            warehouseInStockMapper.insertInventory(warehouseId, goodsNo, number, userId, DateUtils.getNowDate());
        } else {
            warehouseInStockMapper.updateInventory(warehouseId, goodsNo, number, userId, DateUtils.getNowDate());
        }
        return warehouseInStockMapper.updateWarehouseId(warehouseInInfoId, warehouseId);
    }

    @Override
    public Integer updateWarehouseStatus(Integer warehouseInId, Long userId, Date nowDate) {
        return warehouseInStockMapper.updateWarehouseStatus(warehouseInId,userId,nowDate);
    }
}
